import 'dart:io';
import 'dart:typed_data';
import 'dart:ui' as ui show Image;

import 'package:flutter/material.dart';

class ImageUtil {

  static Future<List<int>> getImageSize(String imagePath) async {
    var file = File(imagePath);
    Uint8List byteData = file.readAsBytesSync();
    ui.Image? image = await decodeImageFromList(byteData);
    print('Image width: ${image!.width}, height: ${image.height}');

    return [image.width, image.height];
  }

  static double calcFitImageWidth(int width, int imageWidth, int imageHeight) {
    if(width > imageWidth) {
      return imageWidth + 0.0;
    }
    return width + 0.0;
  }

  static double calcFitImageHeight(double width, int imageWidth, int imageHeight) {
    double rate = width / imageWidth;
    return imageHeight * rate;
  }

}